package org.aurora.core.biz.persistence;

import org.apache.ibatis.annotations.*;
import org.aurora.model.entity.ClientAppInfo;

import java.util.List;
import java.util.Set;

@Mapper
public interface ClientAppMapper {
    String SAVE_BASE_FIELDS = " app_name, appcode, hash_slot ";
    String QUERY_BASE_FIELDS = " id, " + SAVE_BASE_FIELDS;

    String TABLE_NAME = " client_app ";

    @Select("<script> " +
            "select " + QUERY_BASE_FIELDS + " from " + TABLE_NAME +
            " where hash_slot in " +
            "<foreach collection=\"hashSlots\" item=\"hashSlot\" separator=\",\" open=\"(\"  close=\")\"> " +
            "#{hashSlot}" +
            "</foreach> " +
            "</script>")
    List<ClientAppInfo> getClientAppInfosByHashSlots(@Param("hashSlots") List<Integer> hashSlots);

    @Insert("insert into " + TABLE_NAME + " (" + SAVE_BASE_FIELDS + ") " + " values (#{appName}, #{appcode}, #{hashSlot})")
    @SelectKey(statement = "SELECT LAST_INSERT_ID() AS ID", keyProperty = "id", before = false, resultType = Long.class)
    Long saveClientApp(ClientAppInfo clientAppInfo);
}
